package sg.edu.nus.iss.billing.model.subscription;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import sg.edu.nus.iss.billing.controller.BillController;
import sg.edu.nus.iss.billing.model.account.Account;
import sg.edu.nus.iss.billing.model.bill.Bill;
import sg.edu.nus.iss.billing.model.charge.IChargable;

/**
 * @author Ananda, Saravana, BeeHong
 *
 */
public class Subscription implements ISubscription, Serializable {
	private static final long serialVersionUID = 1L;

	List<ISubscribable> services;
	Account subscribingAccount;
	String description;

	private String subscriptionId = null;
	private String dateCommenced = null;
	private String dateTerminated = null;

	public Subscription() {
		this.services = new ArrayList<ISubscribable>();
	}

	public void addService(ISubscribable service) {
		services.add(service);
	}

	public void charge(Bill chargingBill) {
		// get all the charges from the active service under this subscription plan
		List<IChargable> charges = new ArrayList<IChargable>();
		for (ISubscribable service : this.services) {
			if (BillController.isServiceRequiredToBeCharged(service, chargingBill.getBillingPeriod()))
				charges.addAll(service.getCharges());
		}

		chargingBill.setCharges(this, charges);
	}

	public List<ISubscribable> getServices() {
		return this.services;
	}

	public void setServices(List<ISubscribable> services) {
		this.services = services;
	}

	public String getSubscriptionId() {
		return subscriptionId;
	}

	public void setSubscriptionId(String subscriptionId) {
		this.subscriptionId = subscriptionId;
	}

	public String getDateCommenced() {
		return dateCommenced;
	}

	public void setDateCommenced(String dateCommenced) {
		this.dateCommenced = dateCommenced;
	}

	public String getDateTerminated() {
		return dateTerminated;
	}

	public void setDateTerminated(String dateTerminated) {
		this.dateTerminated = dateTerminated;
	}

	public String getDescription() {
		return description;
	}

}
